<template>
	<view class="charts-box">
	  <p align="center" style="color:#7cb5ec">运营版本充值 : {{allValue}}元</p>
	  <br>
	  <qiun-data-charts
		type="column"
		:chartData="recharge"
		background="none"
	  />
	  <p align="center" style="color:#7cb5ec">运营版本ARPU</p>
	  <br>
	  <qiun-data-charts
		type="column"
		:chartData="arpuData"
		background="none"
	  />
	  <p align="center" style="color:#7cb5ec">运营版本角色数 : {{allPlayer}}人</p>
	  <br>
	  <qiun-data-charts
		type="column"
		:chartData="playerData"
		background="none"
	  />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				allValue : 0,
				allPlayer : 0,
				recharge:{},
				arpuData:{},
				playerData:{}
			}
		},
		methods: {
        onLoad() {
            this.getTotalInfo(1)
        },
			//获取版本列表
			getTotalInfo(){
				var self = this
				this.request("/total_info",{},(res) => {
					this.recharge = {
						"categories": [],
						"series": [
							{
								"name": "总充值",
								"data": []
							}
						]
					},
					this.arpuData={
						"categories": [],
						"series": [
							{
								"name": "ARPU",
								"data": []
							}
						]
					},
					this.playerData={
						"categories": [],
						"series": [
							{
								"name": "账号",
								"data": []
							}
						]
					}
					var list = []
					if(res.data){
						console.log(res.data)
						for(var i = 0;i < res.data.length;i++){
							if(res.data[i]["data"]["sync"] == 1){
								if(!res.data[i]["info"]){
									res.data[i]["info"] = {
										amount : 0,
										accNum : 1,
										playerNum : 0
									}
								}
								if(!res.data[i]["info"]["amount"])
									res.data[i]["info"]["amount"] = 0
								if(!res.data[i]["info"]["accNum"])
									res.data[i]["info"]["accNum"] = 1
								if(!res.data[i]["info"]["playerNum"])
									res.data[i]["info"]["playerNum"] = 0
								list.push(res.data[i])
							}
						}
					}
					self.serverData = list
					self.recharge.categories = []
					self.recharge.series[0].data = []
					for(var i = 0;i < list.length;i++){
						self.recharge.categories.push(list[i]["name"])
						self.recharge.series[0].data.push(Number(list[i]["info"]["amount"]))
						this.allValue += Number(list[i]["info"]["amount"])
						this.allPlayer += Number(list[i]["info"]["accNum"])
					}
					self.arpuData.categories = []
					self.arpuData.series[0].data = []
					for(var i = 0;i < list.length;i++){
						self.arpuData.categories.push(list[i]["name"])
						self.arpuData.series[0].data.push((list[i]["info"]["amount"] / list[i]["info"]["accNum"]).toFixed(2))
					}
					self.playerData.categories = []
					self.playerData.series[0].data = []
					for(var i = 0;i < list.length;i++){
						self.playerData.categories.push(list[i]["name"])
						self.playerData.series[0].data.push(list[i]["info"]["accNum"])
					}
				})
			},
            // request请求
            request(path,options,success) {
				this.$axios.post(path,options)//传参
				.then(function(res){
					  success(res)
				})
				.catch(function(err){
					  console.log("请求失败233");
				});
            }
		}
	}
</script>

<style>
.charts-box{
  width: 100%;
  height:300px;
}
</style>
